import AJAX from 'utils/ajax'
import { AUTH_TYPE, UNI_TYPE, CITY_CHANNEL_CODE } from 'utils/config'
import storage from 'utils/helper/storage'

const ajax = new AJAX({
  name: 'api',
  baseURL: '/api/ubd/',
  reponseMsgKey: 'msg',
  reponseCodeKey: 'code',
  reponseSuccessCodes: [0] // 后台请求成功码
})

// 接口请求拦截器
ajax.requestInstance.interceptors.request.use(function (config) {
  config.header = {
    Authorization: storage.get('AUTHORIZATION'),
    ...config.header,
    'city-app-name': 'WEHOTEL',
    'city-channel-code': CITY_CHANNEL_CODE,
    'city-language': 'zh_CN',
    // 先写死这俩值，等新增了渠道再算
    authType: AUTH_TYPE, // 1-锦江app, 5-m站
    uniType: UNI_TYPE // 105-锦江app, 338-m站
    // token: xxxx
  }
  return config
}, function (config) {
  return Promise.reject(config)
})

// 接口返回拦截器
ajax.requestInstance.interceptors.response.use(function (response) {
  return response.data
}, function (error) {
  return Promise.reject(error)
})

export default ajax


// example:
// export  const getList = (parmas, config) => ajax.get('/getList', parmas, { ...config })

// 导出接口
export * from './city.js'
export * from './search.js'
export * from './order.js'
export * from './other.js'
export * from './pay.js'
export * from './product.js'
export * from './user.js'
// #ifdef MP
export * from './mp-login.js'
// #endif

